﻿using System.Threading.Tasks;
using Grpc.Core;
using JESAI.HttpRequestMonitor.Core.Abstracts;
using static JESAI.HttpRequestMonitor.Collector.Grpc.GrpcCollector;

namespace JESAI.HttpRequestMonitor.Collector.Grpc
{
    public class GrpcCollectorService : GrpcCollectorBase
    {
        public IRequestMonitorStorage Storage { get; }

        public GrpcCollectorService(IRequestMonitorStorage storage)
        {
            Storage = storage;
        }

        public override async Task<WriteReply> Write(RequestModelPack request, ServerCallContext context)
        {
            foreach (var item in request.Data)
            {
                await Storage.AddRequestInfoAsync(item.Info, item.Detail);
            }

            return new WriteReply() { Code = 0 };
        }
    }
}